package com.shanjupay.merchant.service;

import com.shanjupay.common.domain.BusinessException;
import com.shanjupay.common.domain.CommonErrorCode;
import com.shanjupay.common.util.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.sql.BatchUpdateException;

/**
 * TODO
 *
 * @Description
 * @Author zhangbing
 * @Date 2024/5/13 17:37
 **/

@Service
public class FileServiceImpl implements FileService{

    @Value("${oss.qiniu.url}")
    private String url;
    @Value("${oss.qiniu.accessKey}")
    private String accessKey;
    @Value("${oss.qiniu.secretKey}")
    private String secretKey;
    @Value("${oss.qiniu.bucket}")
    private String bucket;

    @Override
    public String upload(byte[] bytes, String fileName) throws BatchUpdateException {
        System.out.println(url);
       try {
           //调用common类
           QiniuUtils.upload2Qiniu(accessKey,secretKey,bucket,bytes,fileName);
       }catch (Exception e){
           throw  new BusinessException(CommonErrorCode.E_100106);//上传错误！！
       }
        return url+fileName; //返回一个路径+文件名
    }
}
